package com.arpa.ntocc.basic.api.controller;

import com.arpa.core.web.Result;
import com.arpa.ntocc.basic.api.service.ITableBackupConfigService;
import com.arpa.ntocc.common.common.util.ValidateUtil;
import com.arpa.ntocc.common.controller.BaseController;
import io.swagger.annotations.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @Title 任务处理 Controller
 *
 * @ClassName TaskHandlerController
 * @Author HSL_WITHER
 * @Date 2021_06_08
 * @version 1.1.210608
 *
 */

@Api(tags = "任务处理")
@RestController
@RequestMapping(value = "/cloudTask", produces = "application/json;charset=UTF-8")
@Log4j2(topic = "business")
public class TaskHandlerController extends BaseController {

    @Autowired
    private ITableBackupConfigService iTableBackupConfigService;

    /**
     *
     * @Date
     * @param jobNow, jobValid
     * @return
     */
    @ApiOperation(value = "任务", notes = "备份表数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "授权token", required = true, paramType = "header", dataType = "String", defaultValue = "Bearer 123456"),
            @ApiImplicitParam(name = "deviceId", value = "设备id", paramType = "header", dataType = "string", defaultValue = "0000000000")
    })
    @ApiResponses(@ApiResponse(code = 0, message = "success"))
    @GetMapping(value = "/backupTableData")
    public Result backupTableData(String jobNow, String jobValid) {
        // 校验job请求是否合法
        ValidateUtil.xxlJobValid(jobNow, jobValid);
        try {
            iTableBackupConfigService.backupTableData();
            return Result.ok();
        } catch (Exception e) {
            log.error("备份表数据异常", e);
            return Result.error(e.getMessage());
        }
    }

}
